<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('任务管理')" />
</head>
<body class="gray-bg">
    <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="notice-form">
					<div class="select-list">
						<ul>
							<li>
								流程名称：<input type="text" name="name"/>
							</li>
							<li>
								流程Key：<input type="text" name="key"/>
							</li>
							<li>
								状态：<select name="suspendState" th:with="type=${@dict.getType('bpm_def_status')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm" id="toolbar" role="group">
		        <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="activiti:modeler">
		            <i class="fa fa-plus"></i> 在线绘制流程
		        </a>
		        <a class="btn btn-primary single disabled" onclick="$.operate.editFull()" shiro:hasPermission="activiti:modeler">
		            <i class="fa fa-edit"></i> 部署流程
		        </a>
		        <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="activiti:definition:remove">
		            <i class="fa fa-remove"></i> 删除
		        </a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
	            <table id="bootstrap-table"></table>
	        </div>
    	</div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('activiti:definition:edit')}]];
        var removeFlag = [[${@permission.hasPermi('activiti:definition:remove')}]];
        var types = [[${@dict.getType('sys_notice_type')}]];
        var datas = [[${@dict.getType('bpm_def_status')}]];
        var prefix = ctx + "activiti/definition";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "流程定义管理",
                columns: [
				{
					field : 'name',
					title : '流程名称'
				},
				{
		            field: 'key',
		            title: '流程Key'
		        },
				{
					field: 'version',
					title: '流程版本'
				},
				{
					field: 'deploymentTime',
					title: '部署时间'
				},
				{
		            field: 'suspendState',
		            title: '状态',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	return $.table.selectDictLabel(datas, value);
		            }
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="OnlineModificationProcess(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看</a> ');
		            	if(row.suspendState == "1")
	                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="suspendOrActiveApply(\'' + row.id + '\')"><i class="fa fa-remove"></i>挂起</a>');
		            	else
							actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="suspendOrActiveApply(\'' + row.id + '\')"><i class="fa fa-remove"></i>激活</a>');
						actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.userId + '\')"><i class="fa fa-remove"></i>删除</a> ');
						actions.push('<a href="/js/a/bpm/bpmRuntime/trace?procDef.id=leave:2:1220223296740999168" class="btnList" data-layer="true" title="查看流程图" data-click-binded="true"><i class="fa fa-file-picture-o"></i></a>&nbsp;');
						actions.push('<a href="/js/a/bpm/bpmProcess/resource/xml/leave:2:1220223296740999168" title="查看流程文件" onclick="js.windowOpen(this.href, this.title, 999, 600);return false;"><i class="fa fa-file-excel-o"></i></a>&nbsp;');
						actions.push('<a href="/js/a/bpm/bpmModel/importModel?procDefId=leave:2:1220223296740999168" class="btnList" title="导入到流程模型设计器" data-confirm="是否要将该流程导入到流程模型设计器吗？"data-confirm-success="js.addTabPage($(this),\'业务流程模型\',\'/js/bpm/modeler/index.html#/editor/\'+data.data.id)" data-click-binded="true"><i class="fa fa-file-code-o"></i></a>&nbsp;');
						actions.push('<a href="/js/a/bpm/bpmProcess/updateStatus?key=leave&amp;status=2" class="btnList" title="挂起流程" data-confirm="确认要挂起该流程吗？" data-confirm-success="page();" data-click-binded="true"><i class="glyphicon glyphicon-ban-circle"></i></a>&nbsp;');
						actions.push('<a href="/js/a/bpm/bpmProcess/delete?deploymentId=1220223291011579904" class="btnList" title="删除当前流程版本部署" data-confirm="确认要删除该当前流程版本部署吗？<br/>注意：它会级联删除流程实例及相关的任务。<br/>若不使用建议挂起流程，请谨慎操作！！！" data-click-binded="true"><i class="fa fa-trash-o"></i></a>&nbsp;');
						actions.push('<a href="/js/a/bpm/bpmForm/list?procDefKey=leave&amp;formVersion=2" class="btnList btn-xs" title="关联业务表单" data-click-binded="true"><i class="fa fa-file-text-o"></i> 表单</a>');
						actions.push('<a href="/js/a/bpm/bpmTask/start?id=leave:2:1220223296740999168" class="btnList btn-xs" title="启动调试流程" data-layer="true" data-layer-width="725" data-layer-height="420" data-click-binded="true"><i class="fa fa-play"></i> 调试</a>');
						actions.push('<a href="/js/a/bpm/bpmProcess/export?id=leave:2:1220223296740999168" class="btn-xs" title="导出当前流程版本"><i class="fa fa-file-zip-o"></i> 导出</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });

		function OnlineDrawingProcess() {
			this.modelVisible = true;
			localStorage.setItem("VUE_APP_BASE_API", process.env.VUE_APP_BASE_API)
			this.modelerUrl = "/bpmnjs/index.html?type=addBpmn";
		}

		function OnlineModificationProcess(data) {
			this.modelVisible = true;
			localStorage.setItem("VUE_APP_BASE_API", process.env.VUE_APP_BASE_API)
			this.modelerUrl = '/bpmnjs/index.html?type=lookBpmn&deploymentFileUUID=' + data.deploymentId + '&deploymentName=' + encodeURI(data.resourceName);
		}

		function handleImport() {
			this.upload.title = "上传模型图";
			this.upload.open = true;
		}
    </script>
</body>
</html>